package com.zeedev.flyingsaucer.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.ResourceCursorAdapter;
import mobi.zeedev.flyingsaucer.common.DataModule.MetaBeer;

import java.util.ArrayList;
import java.util.List;

public class StylesCursorAdapter extends ResourceCursorAdapter {

	List<Integer> autoCheck;
	
	public StylesCursorAdapter(Context context, int layout, Cursor c, List<Integer> autoCheckIn) {
		super(context, layout, c);
		this.setAutoCheck(autoCheckIn);
	}
	
	public void setAutoCheck(List<Integer> autoCheckIn) {
		if (autoCheckIn != null) {
			this.autoCheck = autoCheckIn;
		} else{
			this.autoCheck = new ArrayList<Integer>();
		}
	}
	
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		CheckedTextView textView = (CheckedTextView) view.findViewById(android.R.id.text1);
		textView.setText(cursor.getString(cursor.getColumnIndex(MetaBeer.STYLE_NAME)));
		textView.setChecked(autoCheck.contains(cursor.getInt(cursor.getColumnIndex(MetaBeer.STYLE_ID))));
	}

	

}
